﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using pigs;

namespace Pigs.Enemies
{
    class PrairieBoss : pigs.Pig
    {
        Boolean goingUp;// is the pig going up or down on the screen
        HealthBar healthBar;
        GraphicsDevice graphics;
        public int defense = 3;
        public int defenseIncrement = 1;
        public int MAX_DEFENSE = 6;

        public PrairieBoss(Texture2D texture, Vector2 playerPosition, GraphicsDevice gd, int screenWidth)
            : base(texture, playerPosition)
        {
            START_SPEED = 1.00f;
            START_HEALTH = 100;
            this.health = START_HEALTH;
            this.shouldEatSlop = false;
            this.ID = "prairieBoss";
            this.speed = START_SPEED;
            this.isInvincible = true;
            goingUp = true;

            this.graphics = gd;
            this.healthBar = new HealthBar(Color.Green, this.health, gd, new Vector2(50, 50), screenWidth);
        }

        /// <summary>
        /// move to the left until at 400px
        /// after that move up and down
        /// </summary>
        public void Update()
        {

            if (this.position.X > 400)
            {
                this.position.X -= START_SPEED;
            }
            else if (goingUp)
            {
                this.position.Y -= START_SPEED;
                if (position.Y < 150)
                {
                    goingUp = false;
                }
            }
            else
            {
                this.position.Y += START_SPEED;
                if (position.Y > 500 - Height)
                {
                    goingUp = true;
                }
            }
            rectangle = new Rectangle((int)position.X, (int)position.Y, Width, Height);
            healthBar.update(graphics, health);
        }

        /// <summary>
        /// draw the boss
        /// </summary>
        /// <param name="spriteBatch"></param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (healthBar.oldHealth > health)
            {
                spriteBatch.Draw(this.texture, this.position, null, Color.Red, 0f, Vector2.Zero, 1f, effect, 0f);
            }
            else
            {
                spriteBatch.Draw(this.texture, this.position, null, Color.White, 0f, Vector2.Zero, 1f, effect, 0f);
            }
            healthBar.Draw(spriteBatch);
        }
    }
}